<template>
	<view class="content">
		<scroll-view class="header" scroll-x="true" scroll-left="0" :style="{background:$store.state.bgPrimaryColor}">
			<block v-for="(item,index) in columns" :key="index">
				<text :style="{'border-bottom':index == inx ? `3px solid ${$store.state.primaryColor}` : `3px solid transparent`,
				'color':index == inx ? $store.state.primaryColor : '#4C4C4C'}" @click="getindex(item,index)">{{item.name}}</text>
			</block>
		</scroll-view>
		<!-- <u--image :showLoading="true" src="../../static/more.png" width="28rpx" height="28rpx"
			radius="0"></u--image> -->
		<view class="Box">
			<view v-for="(item,index) in lists" :key="index" class="BoxView">
				<view class="BoxOne">
					<u--image :showLoading="true" :src="item.avatar" width="94rpx" height="94rpx" radius="0"></u--image>
					<view class="BoxContent">
						<view class="BoxTop marginBottom">
							<text class="title">{{item.name || ''}}</text>
							<text style="color:#888888;margin-left:15rpx;">{{item.country.name || ''}}教师</text>
						</view>
						<view class="BoxTop">
							<text class="Newtitle">{{item.description || ''}}</text>
						</view>
					</view>
				</view>
				<button @click="linkUrl(`/pages/detail/Teacher_details?id=${item.id}`)"
					:style="{'background':$store.state.buttonColor}">约课</button>
			</view>
		</view>
		<view class="null" v-if="lists.length == 0">
			<u--image :showLoading="true" src="../../static/null.png" width="328rpx" height="328rpx"
				radius="0"></u--image>
		</view>
	</view>
</template>
<script>
	import {
		collectTeacherList,
		teacher_category
	} from '../../api/Teacher.js';
	export default {
		data() {
			return {
				show: false,
				inx: 0,
				columns: [],
				req: {
					shop_id: 1,
					page: 1,
					limit: 10,
					teacher_category_id: ''
				},
				lists: []
			}
		},
		onLoad() {
			this.teacher_category();
			this.collectTeacherList();
		},
		methods: {
			getindex(e, index) {
				this.inx = index;
				this.req.teacher_category_id = e.id;
				this.collectTeacherList();
			},
			/**
			@method 我的收藏老师列表
			**/
			async collectTeacherList() {
				try {
					const res = await collectTeacherList(this.req);
					this.lists = [...res.data.data];
				} catch (err) {
					//TODO handle the exception
					console.log(err);
				}
			},
			/**
			@method 老师分类
			**/
			async teacher_category() {
				try {
					const res = await teacher_category(this.req);
					this.columns = [...[{
						id: '',
						name: '全部'
					}], ...res.data];
				} catch (err) {
					//TODO handle the exception
					console.log(err);
				}
			},
			linkUrl(e) {
				uni.navigateTo({
					url: e
				});
			}
		}
	}
</script>
<style>
</style>
<style scoped lang="scss">
	button::after {
		border: none;
	}

	.content {
		width: 100%;
		background: #F6F7F9;
		min-height: 100vh;

		.null {
			width: 100%;
			display: flex;
			justify-content: center;
			padding-top: 50rpx;
		}

		.header {
			width: 100%;
			white-space: nowrap;
			padding: 10rpx 0rpx 0rpx 20rpx;

			text {
				border-bottom: 3px solid transparent;
				padding-bottom: 20rpx;
				font-family: PingFangSC, PingFang SC;
				font-weight: 600;
				font-size: 28rpx;
				display: inline-block;
				margin-right: 100rpx;
			}

			/deep/ .u-image {
				margin-top: -25rpx;
			}
		}

		.Box {
			.BoxView {
				width: 85%;
				margin: 0px auto;
				background-color: #fff;
				border-radius: 20rpx;
				padding: 30rpx 40rpx 30rpx 40rpx;
				margin-top: 20rpx;
				display: flex;
				justify-content: space-between;
				align-items: center;
			}

			.BoxOne {
				display: flex;
				justify-content: space-between;

				.marginBottom {
					margin-bottom: 10rpx;
				}

				.BoxTop {
					margin-left: 20rpx;
					display: flex;
					align-items: center;

					text {
						display: block;
						font-size: 24rpx;
					}

					.title {
						font-family: PingFangSC, PingFang SC;
						font-weight: 600;
						font-size: 32rpx;
						color: #333333;
						font-style: normal;
					}

					.Newtitle {
						font-family: PingFangSC, PingFang SC;
						font-weight: 500;
						font-size: 24rpx;
						color: #333333;
						font-style: normal;
					}
				}
			}

			button {
				width: 154rpx;
				min-width: 154rpx;
				height: 60rpx;
				background: linear-gradient(270deg, #3078FF 0%, #009DFE 100%);
				border-radius: 46rpx;
				margin: 0px;
				display: flex;
				justify-content: center;
				align-items: center;
				color: #fff;
				font-size: 26rpx;
			}
		}

		.BoxTime {
			display: flex;
			align-items: center;
			margin-top: 20rpx;
			margin-bottom: 20rpx;

			view {
				display: flex;
				align-items: center;

				text {
					margin-left: 10rpx;
					margin-right: 30rpx;
				}
			}
		}
	}
</style>